<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/4/29
 * Time: 15:53
 */
$hostName = env('database.hostname', '127.0.0.1');
$database = env('database.database', '');
$userName = env('database.username', 'root');
$password = env('database.password', '');
$hostPort = env('database.hostport', '3306');
$prefix         = env('database.prefix', '{$prefix}');
$charset = 'utf8mb4';

$pdo = new PDO("mysql:host={$hostName};port={$hostPort}", $userName, $password, array(
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,

));
$pdo->query("USE `{$database}`");

$field = [
    ['name' => $prefix.'amount_log', 'field' => 'is_polymerization', 'desc' =>"tinyint(2) NOT NULL DEFAULT 0 COMMENT '0 不为聚合支付 1 聚合支付'"],
    ['name' => $prefix.'user_consumption', 'field' => 'is_polymerization', 'desc' =>" tinyint(1) NOT NULL DEFAULT 0 COMMENT ' 0 不是 1 是' "],
    ['name' => $prefix.'user_consumption', 'field' => 'open_id', 'desc' =>" varchar(36) NOT NULL DEFAULT '' "],
];

foreach ($field as $value){

    $stmt = $pdo->query("SHOW COLUMNS FROM `{$value['name']}` WHERE `Field` = '{$value['field']}'");
    if (!$stmt->fetch(PDO::FETCH_ASSOC)) {
        // 字段不存在，添加字段
        $sql = "ALTER TABLE `{$value['name']}`  ADD  `{$value['field']}` {$value['desc']} ";
        $pdo->exec($sql);
    }
}


$sql = [
    "update {$prefix}home_template set img='/static/template/aa86a13a3dd7cf6dd0095a1f496ad4a4.png' where id = 1",
    "update {$prefix}home_template set img='/static/template/43711b65099267c06df9bd4ccc88e752.png' where id = 2",
    "update {$prefix}home_template set img='/static/template/7b228159d3e2bfe120c14e04e40b9b44.png' where id = 3",
    "update {$prefix}home_template set img='/static/template/a75234d36a36e2c6b6fa694df53e7468.png' where id = 4",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/1b313202405271746326719.png' where id = 1",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/7cd83202405271746405593.png' where id = 2",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/de40e20240527174719295.png' where id = 3",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/228ec202405271748128880.png' where id = 4",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/547f7202405271748316588.png' where id = 5",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/3acc0202405271748390.png' where id = 6",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/5d9c0202405271748487743.png' where id = 7",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/5b2a8202405271749002155.png' where id = 8",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/f3c06202405271749092848.png' where id = 9",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/708be20240527174917221.png' where id = 10",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/b47f4202405271749247903.png' where id = 11",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/ee929202405271751044635.png' where id = 12",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/26dd6202405271751373393.png' where id = 13",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/60142202405271752252345.png' where id = 14",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/50e7b202405271753353729.png' where id = 24",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/bd011202405271738587704.png' where id = 26",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/b127c202405271739061087.png' where id = 27",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/fe470202405271739169832.png' where id = 28",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/19f82202405271739299268.png' where id = 29",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/d5ab4202405271739511564.png' where id = 30",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/60463202405271740026358.png' where id = 31",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/54554202405271740337962.png' where id = 32",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/6d153202405271740427718.png' where id = 33",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/3dbaf202405271740517667.png' where id = 34",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/ebbb3202405271741016918.png' where id = 35",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/03533202405271741146789.png' where id = 36",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/677cc202405271741461986.png' where id = 37",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/36ff4202405271741572587.png' where id = 38",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/e3f8f202405271742072881.png' where id = 39",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/58f0c202406061017085817.png' where id = 40",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/120b9202406061017198910.png' where id = 41",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/dcd22202406061017288576.png' where id = 42",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/7d058202406061017394929.png' where id = 43",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/8c8f7202405271742193147.png' where id = 49",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/52a42202405271743037945.png' where id = 51",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/4ffb8202405271743131598.png' where id = 52",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/399ce202405271743202815.png' where id = 53",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/5d88420240527174327134.png' where id = 54",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/ed577202405271744183890.pngg' where id = 55",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/ed577202405271744183890.png' where id = 56",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/de7bb202405271744439548.png' where id = 57",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/b7482202405271744551306.png' where id = 58",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/fef1220240527174502463.png' where id = 59",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/8be63202405271745101661.png' where id = 60",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/43474202405271745181570.png' where id = 61",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/ed182202405271745262340.png' where id = 62",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/a0e47202405271745321088.png' where id = 63",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/67ae7202405271745398981.png' where id = 64",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-05-27/8e8802024052717454648.png' where id = 74",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/b7aab202406061025091037.png' where id = 76",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/10292202406061025172139.png' where id = 77",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/919f020240606102527512.png' where id = 78",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/23fe0202406061025379043.png' where id = 79",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/fcf3c202406061025494666.png' where id = 80",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/b5c9a202406061026175689.png' where id = 81",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/b69d220240606102605414.png' where id = 82",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/54ad020240606102628301.png' where id = 83",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/e9657202406061026381137.png' where id = 84",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/742f9202406061026478072.png' where id = 85",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/52bce202406061027159159.png' where id = 86",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/ed037202406061027224860.png' where id = 87",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/52bce202406061027159159.png' where id = 88",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/0c13c202406061027471695.png' where id = 89",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/58f0c202406061017085817.png' where id = 90",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/120b9202406061017198910.png' where id = 91",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/7d058202406061017394929.png' where id = 92",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/7d058202406061017394929.png' where id = 93",
    "update {$prefix}home_module set icon='https://n8.weijuyunke.com/2024-06-06/81f0e202406061027568950.png' where id = 99",
    "DELETE  from{$prefix}home_module where id = 50",
    "DELETE  from{$prefix}home_module where id = 75",
    "DELETE  from{$prefix}home_module where id = 100",
   /* "CREATE TABLE IF NOT EXISTS  `{$prefix}bargaining_goods` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `main_img` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `details` text COLLATE utf8_unicode_ci NOT NULL,
  `original_price` decimal(12,2) NOT NULL DEFAULT '0.00',
  `min_price` decimal(12,2) NOT NULL DEFAULT '0.00',
  `reduce_min_amount` decimal(12,2) NOT NULL DEFAULT '0.00',
  `reduce_max_amount` decimal(12,2) NOT NULL DEFAULT '0.00',
  `start_time` bigint(12) NOT NULL DEFAULT '0',
  `end_time` bigint(12) NOT NULL DEFAULT '0',
  `create_time` bigint(12) NOT NULL DEFAULT '0',
  `ginseng_num` int(10) NOT NULL DEFAULT '0',
  `false_ginseng_num` int(10) NOT NULL DEFAULT '0',
  `status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1 启用 2 禁用 3 过期',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci",
    "CREATE TABLE IF NOT EXISTS  `{$prefix}bargaining_order` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `sn_order` varchar(36) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `bargaining_id` int(11) NOT NULL DEFAULT '0',
  `uid` int(11) NOT NULL DEFAULT '0',
  `original_price` decimal(12,2) NOT NULL,
  `amount_price` decimal(12,2) NOT NULL,
  `participate_num` int(5) NOT NULL DEFAULT '0',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1 ，待支付2 支付等待回调 3 支付成功 待发货 4 发货中 5 完成 6 申请退款 7 退款成功',
  `end_time` bigint(12) NOT NULL DEFAULT '0',
  `create_time` bigint(12) NOT NULL,
  `address_id` int(11) NOT NULL DEFAULT '0',
  `pay_way` tinyint(2) NOT NULL DEFAULT '1' COMMENT '1 微信 2 支付宝 3 余额',
  `pay_destination` tinyint(2) NOT NULL DEFAULT '1' COMMENT '1 不是微信支付 2 普通商户 3 服务商 ',
  `take_over_way` tinyint(1) NOT NULL DEFAULT '1' COMMENT ' 1门店自取 2 送货上门''',
  `lowest_price` decimal(12,2) NOT NULL DEFAULT '0.00',
  `bargaining_people_number` int(5) NOT NULL DEFAULT '1',
  `staff_id` int(11) NOT NULL DEFAULT '0',
  `store_id` int(11) NOT NULL DEFAULT '0',
  `rand_code` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `express_name` varchar(100) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `express_phone` varchar(100) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci",
    "CREATE TABLE IF NOT EXISTS  `{$prefix}bargaining_log` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `bargaining_order_id` int(11) NOT NULL DEFAULT '0',
  `bragaining_id` int(11) NOT NULL,
  `uid` int(11) NOT NULL,
  `amount` decimal(12,0) NOT NULL DEFAULT '0',
  `create_time` bigint(12) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"*/
];

$conn = new mysqli($hostName, $userName, $password, $database);
foreach ($sql as $value){

    $conn->query($value);
}

// 关闭连接
$conn->close();
